package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SalaryBillFieldsAddDTO;
import org.jsola.hr.dto.SalaryBillFieldsUpdateDTO;
import org.jsola.hr.entity.SalaryBillFieldsDO;
import org.jsola.hr.query.SalaryBillFieldsQuery;
import org.jsola.hr.service.ISalaryBillFieldsService;
import org.jsola.hr.vo.SalaryBillFieldsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 工资条自定义字段
 *
 * @author zhr
 */
@Component
public class SalaryBillFieldsTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISalaryBillFieldsService salaryBillFieldsService;

    /**
     * 生成add测试数据
     * @return SalaryBillFieldsAddDTO
     */
    public SalaryBillFieldsAddDTO getSalaryBillFieldsAddDTO(){
        SalaryBillFieldsAddDTO salaryBillFieldsAddDTO = new SalaryBillFieldsAddDTO();
        salaryBillFieldsAddDTO.setBillId(getRandomValue("varchar",32));
        salaryBillFieldsAddDTO.setFieldName(getRandomValue("varchar",255));
        salaryBillFieldsAddDTO.setFieldValue(getRandomValue("varchar",255));
        salaryBillFieldsAddDTO.setNeedCalculate(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        salaryBillFieldsAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",11)));
        return salaryBillFieldsAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SalaryBillFieldsUpdateDTO
     */
    public SalaryBillFieldsUpdateDTO getSalaryBillFieldsUpdateDTO(SalaryBillFieldsVO salaryBillFieldsVO){
        return salaryBillFieldsService.selectDOById(salaryBillFieldsVO.getId(), SITE_ID).to(SalaryBillFieldsUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SalaryBillFieldsQuery
     */
    public SalaryBillFieldsQuery getSalaryBillFieldsQuery() {
        SalaryBillFieldsQuery salaryBillFieldsQuery = new SalaryBillFieldsQuery();
        List<SalaryBillFieldsDO> salaryBillFieldsDOList = salaryBillFieldsService.list(new SalaryBillFieldsDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(salaryBillFieldsDOList)) {
            SalaryBillFieldsDO salaryBillFieldsDO = salaryBillFieldsDOList.get(0);
            salaryBillFieldsQuery = salaryBillFieldsDO.to(SalaryBillFieldsQuery.class);
        }
        return salaryBillFieldsQuery;
    }

    /**
     * 保存示例
     * @return SalaryBillFieldsVO
     */
    public SalaryBillFieldsVO saveSalaryBillFieldsExample(){
        SalaryBillFieldsAddDTO addDTO = this.getSalaryBillFieldsAddDTO();
        SalaryBillFieldsVO salaryBillFieldsVO = salaryBillFieldsService.save(addDTO,buildTokenUser());
        return salaryBillFieldsVO;
    }


}

